package com.feeyo.prophet.config;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;

import java.util.concurrent.TimeUnit;

public class ChatCache {

    private static final Cache<String, String> cache = CacheBuilder.newBuilder()
            .expireAfterWrite(3, TimeUnit.MINUTES) // 设置过期时间
            .maximumSize(6000) // 设置最大容量
            .build();

    /**
     * 增加数据
     */
    public static void addToCache(String key, String item) {
        cache.put(key, item);
    }

    /**
     * 获取数据
     */
    public static String getCacheByKey(String key) {
        return cache.getIfPresent(key);
    }


    /**
     * 删除数据
     */
    public static void removeCacheById(String key) {
        cache.invalidate(key);
    }



}
